#include "PreCompiledHeader.h"
#include "System.hpp"
#include "Window.hpp"
#include "Renderer.hpp"


System *System::s_system = 0;

/****************************************************************************/
/*!

  Get System (Singleton Design)

*/
/****************************************************************************/
System * System::GetSystem()
{
    if(!s_system)
    {
        s_system = new System();
    }
    return s_system;
}

/****************************************************************************/
/*!

  Delete System (Singleton Design)

*/
/****************************************************************************/
void System::DeleteSystem()
{
    delete s_system;
}

/****************************************************************************/
/*!

  System Initialize

*/
/****************************************************************************/
bool System::Initialize()
{
     bool initOk = true;
    m_Window = new Window();
    m_Window->Initialize();
    
	
   
    // Initialize graphics using client area size
    m_Renderer = new Renderer();
    
	if(!m_Renderer->Initialize(m_Window->GetHandle(),m_windowWidth,m_windowHeight))
	{
		initOk = false;
	}
    m_Renderer->InitializeResource();
	
	return initOk;
}

/****************************************************************************/
/*!

  Update System

*/
/****************************************************************************/
void System::Update()
{
    m_Window->UpdateWindow(); // Update Window
}

/****************************************************************************/
/*!

  Shut Down System

*/
/****************************************************************************/
void System::Shutdown()
{

    m_Window->ShutdownWindow();
    if(m_Window != NULL)
    {
        delete m_Window;
        m_Window = 0;
    }

    m_Renderer->ReleaseResources();
    if(m_Renderer != NULL)
    {
        delete m_Renderer;
        m_Renderer = NULL;
    }

    DeleteSystem();
}

/****************************************************************************/
/*!

  Get Window

*/
/****************************************************************************/
Window * System::GetWindow()
{
    return m_Window;
}

/****************************************************************************/
/*!

  Get Renderer

*/
/****************************************************************************/
Renderer* System::GetRenderer()
{
    return m_Renderer;
}

/****************************************************************************/
/*!

  Constructor, initialise all member values to 0.

*/
/****************************************************************************/
System::System()
{
    m_windowWidth  = 800;
	m_windowHeight = 600;

    m_Window = 0;
    m_Renderer = 0;
}

/****************************************************************************/
/*!

  Get Window Width. Including borders.

*/
/****************************************************************************/
int System::GetWindowWidth() const
{
    return m_windowWidth;
}

/****************************************************************************/
/*!

  Get Window Height. Including borders.

*/
/****************************************************************************/
int System::GetWindowHeight() const
{
    return m_windowHeight;
}

